<?php	
	include 'db.php';
	//session_start();
	function tabIsActive($page, $targetPage){
		$classval = ($page == $targetPage)?'active':'adminTab';
		echo $classval;
	}
	include('categorytree.php');
	
	// products - add
	function showProductAdd(){
  ?>
  		<script type="text/javascript">
			function ChooseCategory(caption,val){
				if(document.getElementById(val.id).checked==true){
					var findnow = $('.cateholder div.cateholder_canvas').find('#_cat_'+val.value).attr('class');
					if(!findnow){
					var oldcon = $('.cateholder div.cateholder_canvas').html();
				$('.cateholder div.cateholder_canvas').html(oldcon+"<div class=\"cateholder_ele\" id=\"_cat_"+val.value+"\"><a href=\"javascript:void(0)\" onclick=\"RemoveCatSel('_cat_"+val.value+"')\"><i class=\"icon-remove-sign\"></i> "+caption+"</a><input type=\"hidden\" name=\"addcat[]\" id=\"cat_"+val.value+"\" value=\""+val.value+"\" /></div>");
					}else{
						return false;
					}
				}else{
					$('#_cat_'+val.value).remove();
				}
				
			}
			function RemoveCatSel(obj){
				$('#'+obj).remove();
			}
			function Try(){
				for(var cnt = 1;cnt<=$('#catcnter').val();cnt++){
					document.getElementById('cat_check_'+cnt).checked = false;
				}
			}
		</script>
		<div class="tab-pane active" id="product-add">
            	<div class="row">
                <a href="led-master.php?mngr=prod&subpg=update" style="float:right; padding-top:5px;">Back &raquo;</a>
                	<h3 class="economicaBold">ADD PRODUCTS</h3>
                    <div class="rounded  box_shadow box-align-center">                
            <form action="inc/products/addproduct.inc.php" method="post" enctype="multipart/form-data">
              <fieldset>   
			  
			  <div class="j-add-left">            
                
                 <label>MAG Description</label>
                <input type="text" name="magDesc" id="magDesc"  placeholder="MAG Description">
                
                <label>Category</label>
                 <a class="updateLink" rel="tooltip" title="Images" data-toggle="modal" href="#img_itemModal_add_category" onclick="Try()"><i class="icon-plus-sign"></i> Add Category</a>
                 <div class="cateholder">
                 	<div class="cateholder_canvas">
                        
                    </div>
                    <div class="clear"></div>
                 </div>
                 <div id="img_itemModal_add_category" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-header">
                        
                        <h1>Select Categories</h1>
                        <div style="height:350px; overflow-y:auto;">
                            <ul class="j-categories">
                                <?php
                                $categories = mysql_query("SELECT * FROM category WHERE parent is NULL ORDER BY name");
                                $cnter = 0;
                                while($catrow = mysql_fetch_array($categories)){
                                    $cnter++;
                                ?>
                                <li>
                                <?php
									$checkifpar = mysql_query("SELECT id FROM category WHERE parent = ".$catrow['id']);
									$able = (mysql_num_rows($checkifpar))? "disabled = \"disabled\"" : NULL;
								?>
                                    <input type="checkbox" id="cat_check_<?php echo $cnter; ?>" value="<?php echo $catrow['id'] ?>" onclick="ChooseCategory('<?php echo $catrow['name']; ?>',this)">&nbsp;&nbsp;<?php echo $catrow['name']; ?>
                                     <?php
										if(mysql_num_rows($checkifpar)){
											$getchild = ShowChild_PopUp($catrow['id'],$cnter);
											echo $getchild ['str'];
											$cnter = $getchild ['cnt'];
										}
                                	?>
                                </li>
                                <?php	
                                    }
                                ?>
                                
                            </ul>
                        </div>
                        
                        <input type="hidden" id="catcnter" value="<?php echo $cnter; ?>" />	
                        </div>
                         	<div class="modal-footer">
								<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 			
							</div>
                   </div>
                 
                
                 <label>PH Code</label>
                <input type="text" name="phCode" id="phCode"  placeholder="Ph Code">
               
                <label>Item Name</label>
                <input type="text" name="itemName" id="itemName"  placeholder="name of item">
                <span class="help-block">Type in the name of the item you want to add.</span>
                
                <label>Item Description</label>
                <input type="text" name="itemDesc" id="itemDesc"  placeholder="description of item">
                <span class="help-block">Type in the description of the item you want to add.</span>
                
                <label>Item Price</label>
                <input type="text" name="itemPrice" id="itemPrice"  placeholder="Price of item">
                <span class="help-block">Type in the Price of the item.</span>       	 
             	<label>Wattage</label>
                <input type="text" name="watts" id="watts"  placeholder="Wattage">
                    
                <label>Comparable Halogen Wattage</label>
                <input type="text" name="chw" id="chw"  placeholder="Comparable Halogen Wattage">
                    
                <label>Socket</label>
                <input type="text" name="socket" id="socket"  placeholder="Socket">
                    
               	<!--<label>Bulb Shape</label>
                <input type="text" name="bshape" id="bshape"  placeholder="Bulb Shape here">-->
					
				<label>Beam Intensity</label>
                <input type="text" name="binsten" id="binsten"  placeholder="Beam Intensity">
					
				</div>
				<div class="j-div-right">		
                    
                    
                    
                   <label>Beam Angle</label>
                    <input type="text" name="bangle" id="bangle"  placeholder="Beam Angle">
                    
                    <label>LifeTime</label>
                    <input type="text" name="lifetime" id="lifetime"  placeholder="Lifetime">
                                
                    <label>Dimmable*</label>
                    <select name="dimmable" id="dimmable">
                      <option value="1">Yes</option>
                      <option value="0">No</option>              
                    </select>
                    
                    <label>Lumen Output</label>
                    <input type="text" name="lumout" id="lumout"  placeholder="Lumen Output">
                    
                    <label>Efficacy</label>
                    <input type="text" name="effi" id="effi"  placeholder="Efficacy">
                    
                    <label>Units Per Pack</label>
                    <input type="text" name="upp" id="upp"  placeholder="Units Per Pack">
                    
                     <label>Color Rendering Index</label>
                    <input type="text" name="cri" id="cri"  placeholder="Color Rendering Index">
                    
                    <label>Color Temperature</label>
                    <input type="text" name="colorTemp" id="colorTemp"  placeholder="Color Temperature">
                    
                    <label>12NC 929000</label>
                    <input type="text" name="nc" id="nc"  placeholder="12NC 929000">
					
                    
					
						<label>Product Image</label>
						<input id="lefile" type="file" name="pimg" style="display:none">
						<div class="input-append">
						   <input id="photoCover" class="input-large" type="text">
						   <a class="btn" onclick="$('input[id=lefile]').click();">Browse</a>
						</div>
						 
						<script type="text/javascript">
						$('input[id=lefile]').change(function() {
						   $('#photoCover').val($(this).val());
						});
						</script>
					
					
					<p></p>
					
					
                    <p>            
                    <button type="submit" class="btn">Submit</button>
					</p>
				</div>
				<div class="clear"></div>
                  </fieldset>
                </form>
                    </div>
                </div>
            </div>
		<?php
	}
	// products - update
	function showProductUpdate(){
	?>
    	<script type="text/javascript">
			function RemoveItemJ(url){
				if(confirm('Move item to trash?')){
					window.location = url;
				}else{
					return false;
				}
			}
		</script>
		<!-- start product-update -->
  			<div class="tab-pane active" id="product-update">
            	<!-- start row -->
            	<div class="row">
                	<div><h3 class="economicaBold">UPDATE PRODUCTS</h3></div>
                    <!-- start update products --> 
                    <div class="rounded  box_shadow box-align-center" id="products_admin">  
                    
                    <script type="text/javascript">
						function ProdAccor(id,obj){
							$('#products_admin').find('.child_holders').slideUp(300);
							$('.parent_').find('i').attr('class','icon-chevron-down');
							if($('#child_'+id).css('display')=='block'){
								$(obj).find('i').attr('class','icon-chevron-down');
								$('#child_'+id).slideUp(300);
							}else{
								$(obj).find('i').attr('class','icon-chevron-up');
								$('#child_'+id).slideDown(300);
							}
						}
					</script>
                   <?php 
				   
				   		$get_parents = mysql_query("SELECT * FROM category WHERE parent is not null");
						while($get_par_list = mysql_fetch_array($get_parents)) {
				   ?> 
                    
                    <div class="parent_" style="background:#F0F0F0; border-bottom:1px solid #CCC;">
                    	<div style="width:800px; float:left; padding:10px; font-size:15px;">
                        	<a href="javascript:void(0);" onclick="ProdAccor(<?php echo $get_par_list['id']; ?>,this)"><i class="icon-chevron-down" ></i> <strong><?php echo $get_par_list['name']; ?></strong> </a> <span style="color:#0C0; font-size:11px; font-style:italic;"><?php  if($get_par_list['type']=='Y') echo "(Dimmable)"; else if($get_par_list['type']=='N') echo "(Non Dimmable)"; else if($get_par_list['type']=='B') echo "(Dimmable/Non Dimmable)"; ?></span>
                        </div>
                        <div style="width:75px; float:right; padding:10px;" align="right">
                        	<a href="led-master.php?mngr=prod&subpg=upload&parent=<?php echo $get_par_list['id']; ?>"><i class="icon-upload"></i> Upload</a>
                        </div>
                        
                        <div class="clear"></div>
                    </div>
                    
                    <div id="child_<?php echo $get_par_list['id']; ?>" class="child_holders" style="display:none;">
                      
                    	<table id="product-update-table" class="table table-striped table-hover">
                        <!-- start thead -->
                        <thead>
                        	<tr>
                            	
                                <td>Item Name</td>
                                <td>Item Description</td>
                                <td>MAG Description</td>
                                <td>PH Code</td>
                                <td>Item Price</td>
                                <td>Wattage</td>
                              
								<td>Action</td>
					                          
                            </tr>                            
                         </thead>
                         <tbody>
         
         <?php
			$sql = "SELECT * FROM items LEFT OUTER JOIN cat_items ON cat_items.item_id = items.itemId WHERE items.isActive = 1 AND cat_items.cat_id = ".$get_par_list['id']." ORDER BY items.itemID DESC";		
  		if ($result=mysql_query($sql)) {// check if query has contents
			while ($row=mysql_fetch_array($result)) {// start fetching arrays 
			
			if(strlen($row['image'])>0)
				$img = '<img src="'.str_replace("../../","",$row['image']).'" align="left" width="350" />';
			else
				$img = '<img src="productimages/noimage.jpg" align="left" width="350" />';
		?>		
			<tr>
                   
                                <td><a class="updateLink" rel="tooltip" title="Update <?php echo$row['itemName'].' '.$row['itemDesc']; ?>" data-toggle="modal" href="#itemModal<?php echo $row['itemId']; ?>"><?php echo $row['itemName']; ?></a>
								
								<div class="j-modal">
                                    <div id="itemModal<?php echo $row['itemId']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width:800px;">
                                            <div class="modal-header">
                                            
                                            <?php echo $img; ?>
                                            <p>
                                            <table width="300" style="float:right;">
                                            
                                            <tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Comparable Halogen Wattage</td>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['halogenWatt']; ?></td>
                                           	</tr>
                                             <tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Socket</td>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['socket']; ?></td>
                                            </tr>
                                             <tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Beam Intensity</td>
                                                 <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['beamInt']; ?></td>
                                            </tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Beam Angle</td>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['beamAngle']; ?></td>
                                            </tr>
                                             <tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Lifetime</td>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['lifetime']; ?></td>
                                            </tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Dimmable</td>
                                                 <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['dimmable']; ?></td>
                                              
                                            </tr>
                                            <tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Lumen Output</td>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['lumenOutput']; ?></td>
                                              </tr>
                                            <tr>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;">Efficacy</td>
                                                <td style="background:#FFF; border-bottom:1px solid #f8f8f8;"><?php echo $row['efficacy']; ?></td>
                                             </tr>
                                             </table>
                                            </p>
                                            <div class="clear"></div>
                                            </div>
                                            <div class="modal-footer">
                                                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
                                                
                                              </div>
                                    </div>	
                                </div>
								</td>
                                <td><?php echo $row['itemDesc']; ?></td>
                                <td><?php echo $row['magDesc']; ?></td>
                                <td><?php echo $row['phCode']; ?></td>
                                <td><?php echo $row['itemPrice']; ?></td>
                                <td><?php echo $row['wattage']; ?></td>
                              
								<td><a href="led-master.php?mngr=prod&subpg=update2&id=<?php echo $row['itemId']; ?>" title="edit" class="updateLink"><i class="icon-pencil"></i></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:void(0);" title="delete" class="updateLink" onclick="RemoveItemJ('inc/products/deleteproduct.inc.php?action=remove&iid=<?php echo $row['itemId']; ?>')"><i class="icon-trash"></i></a></td>  
								                     
                            </tr>
          <?php
			} 
		}
       
		?>
                        	                     
                    </tbody>                        
                         </table>
                         	</div>
                           <?php
						}
						   ?>
                         
                    </div>
                    <!-- end update products -->
                </div>
                <!-- end row -->
            </div>
            <!-- end product-update -->;
	<?php	
	}
	
	//products - delete
	function showProductDelete(){
		$sql = "SELECT * FROM items WHERE isActive = 0 ORDER BY itemName";
	?>	
		<!-- start product-delete -->
  			<div class="tab-pane active" id="product-delete">
            	<!-- start row -->
            	<div class="row">
					<a href="led-master.php?mngr=prod&subpg=update" style="float:right; padding-top:5px;">Back &raquo;</a>
                	<h3 class="economicaBold">DELETE PRODUCTS</h3>
                    <!-- start delete products --> 
                    <div class="rounded  box_shadow box-align-center">    
                    	<table id="product-delete-table" class="table table-striped table-hover">
							<thead>
								<tr>
									<td>Action</td>	
									<td>Item Name</td>	
									<td>Item Description</td>							
								</tr>
							</thead>
							<tbody>
            <?php
			if ($result=mysql_query($sql)) {// check if query has contents
				while ($row=mysql_fetch_array($result)) {// start fetching arrays 
					$itemStat = ($row['isActive'] == 1)?'<a href="inc/products/deleteproduct.inc.php?action=remove&iid='.$row['itemId'].'"><i class="icon-remove"></i> delete</a>':'<a href="inc/products/deleteproduct.inc.php?action=restore&iid='.$row['itemId'].'"><i class="icon-ok"></i> restore</a>';
					$html .= '<tr>';
					$html .= '<td>'.$itemStat.'</td>';
					$html .= '<td>'.$row['itemName'].'</td>';
					$html .= '<td>'.$row['itemDesc'].'</td>';
				}
				echo @$html;
			}
		?>			
				</tbody>
						</table>
                    </div>
                    <!-- end delete products -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end product-delete	-->
       <?php
		
	}// end showProductDelete function 
	
	//customer - show
	function showCustomers(){
		$sql = "SELECT * FROM customers";
		$html = '<!-- start customer-view -->
  			<div class="tab-pane active" id="customer-view">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">VIEW CUSTOMERS</h3>
                    <!-- start delete products --> 
                    <div class="rounded  box_shadow box-align-center">    
                    	<table id="customers-view-table" class="table table-striped table-hover">
							<thead>
								<tr>
									<td>Name</td>	
									<td>Job Title</td>	
									<td>Location</td>
									<td>P.O Box</td>
									<td>Email</td>
									<td>Mobile Number</td>
									<td>Company Name</td>															
								</tr>
							</thead>
							<tbody>';
			if ($result=mysql_query($sql)) {// check if query has contents
				while ($row=mysql_fetch_array($result)) {// start fetching arrays 
						$html .= '<tr>';
						$html .= '<td>'.$row['cName'].'</td>	
								  <td>'.$row['cJobTitle'].'</td>	
									<td>'.$row['cLocation'].'</td>
									<td>'.$row['cPO'].'</td>
									<td>'.$row['cEmail'].'</td>
									<td>'.$row['cNumber'].'</td>
									<td>'.$row['cCompName'].'</td>															
								</tr>';			
				}
			}
			$html .= '</tbody></table></div>
                    <!-- end view customer -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end customer-view	-->';
		echo $html;
	}// end showCustomers function
	
	//customer - edit
	function showCustomersEdit(){
		$sql = "SELECT * FROM customers WHERE isActive = 1";
	?>
		<script type="text/javascript">
			function RemoveItemJ(url){
				if(confirm('Move item to trash?')){
					window.location = url;
				}else{
					return false;
				}
			}
		</script>
  			<div class="tab-pane active" id="customer-view">
            	
            	<div class="row">
                	<h3 class="economicaBold">CUSTOMERS</h3>
                    
                    <div class="rounded  box_shadow box-align-center">    
                    	<table id="customers-edit-table" class="table table-striped table-hover" width="100%">
							<thead>
								<tr>
									
									<td width="16%">Name</td>	
									<td width="14%">Job Title</td>	
									<td width="11%">Location</td>
									<td width="12%">P.O Box</td>
									<td width="11%">Email</td>
									<td width="11%">Mobile Number</td>
									<td width="15%">Company Name</td>	
									<td width="10%">Action</td>														
								</tr>
							</thead>
							<tbody>
      <?php
			if ($result=mysql_query($sql)) {// check if query has contents
				while ($row=mysql_fetch_array($result)) {// start fetching arrays 
	 ?>
					<tr>					
						<td><?php echo $row['cName']; ?></td>	
						<td><?php echo $row['cJobTitle']; ?></td>	
						<td><?php echo $row['cLocation']; ?></td>
						<td><?php echo $row['cPO']; ?></td>
						<td><?php echo $row['cEmail']; ?></td>
						<td><?php echo $row['cNumber']; ?></td>
						<td><?php echo $row['cCompName']; ?></td>
						<td><a class="edit-customer" rel="tooltip" title="Edit <?php echo $row['cName']; ?>" data-toggle="modal" href="led-master.php?mngr=cust&subpg=edit&eid=<?php echo $row['customerID'];  ?>"><i class="icon-pencil"></i></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a class="edit-customer" rel="tooltip" title="Move <?php echo $row['cName']; ?>" data-toggle="modal" href="javascript:void(0);" onclick="RemoveItemJ('inc/customers/deletecustomer.inc.php?action=remove&cid=<?php echo $row['customerID'];  ?>')"><i class="icon-trash"></i></a></td>															
					</tr>
     <?php			
				}
			}
	?>
			</tbody></table></div>
                </div> 
            </div> 	
	<?php
	}
	
	function showCustomerDelete(){
		$sql = "SELECT * FROM customers WHERE isActive = 0";
		$html = '<!-- start customer-delete -->
  			<div class="tab-pane active" id="customer-delete">
            	<!-- start row -->
            	<div class="row">
					<a style="float:right; padding-top:5px;" href="led-master.php?mngr=cust&amp;subpg=view">Back »</a>
                	<h3 class="economicaBold">DELETE CUSTOMERS</h3>
                    <!-- start delete customer --> 
                    <div class="rounded  box_shadow box-align-center">    
                    	<table id="customers-edit-table" class="table table-striped table-hover">
							<thead>
								<tr>
									<td>Action</td>
									<td>Name</td>	
									<td>Job Title</td>	
									<td>Location</td>
									<td>P.O Box</td>
									<td>Email</td>
									<td>Mobile Number</td>
									<td>Company Name</td>															
								</tr>
							</thead>
							<tbody>';
		if ($result=mysql_query($sql)) {// check if query has contents
				while ($row=mysql_fetch_array($result)) {// start fetching arrays 
					$itemStat = ($row['isActive'] == 1)?'<a href="inc/customers/deletecustomer.inc.php?action=remove&cid='.$row['customerID'].'"><i class="icon-remove"></i> remove</a>':'<a href="inc/customers/deletecustomer.inc.php?action=restore&cid='.$row['customerID'].'"><i class="icon-ok"></i> restore</a>';					
					$html .= '<tr>
									<td>'.$itemStat.'</td>
									<td>'.$row['cName'].'</td>	
									<td>'.$row['cJobTitle'].'</td>	
									<td>'.$row['cLocation'].'</td>
									<td>'.$row['cPO'].'</td>
									<td>'.$row['cEmail'].'</td>
									<td>'.$row['cNumber'].'</td>
									<td>'.$row['cCompName'].'</td>															
								</tr>';
				}				
		}
				
		$html .= '</tbody></table></div>
                    <!-- end delete customer -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end customer-delete	-->';
		echo $html;
	}
	
	function InvoiceDetail($rid,$cid,$pid){
				$items = mysql_query("SELECT items.itemDesc as itemDesc, items.itemPrice as itemPrice,`order`.qty as qty FROM receipts LEFT OUTER JOIN `order` ON `order`.receipt_id = receipts.receiptID LEFT OUTER JOIN items ON items.itemId = `order`.item_id WHERE receipts.receiptID = $rid AND `order`.customer_id = $cid AND receipts.proformaID = '$pid'");
							
					$data_items = array();
					while($itemslist = mysql_fetch_array($items)){
						$data_items[] = $itemslist;
					}
					$stritem = NULL;
					$stritem = "
					<table width=\"100%\" border=\"0\" id=\"invoice-view-table\" class=\"table table-striped table-hover\">
					<tr>
						<th width=\"70%\">Item</th>
						<th width=\"10%\">Qty</th>
						<th width=\"20%\"><div align=\"right\">Price</div></th>
					</tr>
					";
					$amount = 0;
					$totalammount = 0;
					foreach($data_items as $rowval){
						$amount = $rowval['qty'] * $rowval['itemPrice'];
						$totalammount = $amount + $totalammount;
						$stritem .= "<tr>
										<td>".$rowval['itemDesc']."</td>
										<td>".$rowval['qty']."</td>
										<td><div align=\"right\">".number_format($amount, 2, '.', '')." AED</div></td>
									</tr>
									";
					}
					
					return $stritem."
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td><div align=\"right\"><strong>Total Amount: &nbsp;&nbsp;&nbsp;".number_format($totalammount, 2, '.', '')." AED</strong></div></td>
					</tr>
					</table>";
		
	}
	
	function InvoiceDetails(){
?>
	<div class="tab-pane active" id="receipts-view">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">VIEW INVOICES DETAILS</h3>
                    <!-- start delete products --> 
                    <div class="rounded box_shadow box-align-center">    
                    	<?php echo InvoiceDetail(@$_GET['inid'],@$_GET['cid'],@$_GET['pid']); ?>
                    </div>
                </div>
    </div>
<?php	
	}
	
	//invoice - show
	function showInvoice(){
		
		$percount = 10;
		if(@$_GET['page']){
			$pageget = $_GET['page'];
			$pageget-=1;
			$pageget = $pageget*10;
		}else{
			$pageget = 0;
		}
		$limit = "LIMIT $pageget, $percount";
		
		include('pagination/usage.php');
			
		$sql = "SELECT * FROM receipts ORDER BY receiptID DESC $limit";
		
		?>
        
		<!-- start receipts-view -->
  			<div class="tab-pane active" id="receipts-view">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">VIEW INVOICES</h3>
                    <!-- start delete products --> 
                    <div class="rounded box_shadow box-align-center">    
                    	<table id="invoice-view-table" class="table table-striped table-hover">
							<thead>
								<tr>
									<td>Proforma ID</td>	
									<td>Customer Name</td>	
									<td>Job Title</td>
									<td>P.O Box</td>
									<td>Address</td>
									<td>Mobile Number</td>
									<td>Salesman</td>
									<td>Date</td>
									<td>Items</td>														
								</tr>
							</thead>
							<tbody>
            <?php
			if ($result=mysql_query($sql)) {// check if query has contents
				while ($row=mysql_fetch_array($result)) {// start fetching arrays 
			?>		
					
					
						<tr>
						<td><?php echo $row['proformaID']; ?></td>	
								  <td><?php echo $row['custName']; ?></td>	
									<td><?php echo $row['custJobTitle']; ?></td>
									<td><?php echo $row['custPO']; ?></td>
									<td><?php echo $row['custLocation']; ?></td>
									<td><?php echo $row['custNumb']; ?></td>
									<td><?php echo $row['receiptDate']; ?></td>		
									<td><?php echo $row['salesman']; ?></td>
									<td>
										<a class="view-invoice" rel="tooltip" title="View Purchases" href="led-master.php?mngr=inv&subpg=invoicedetail&inid=<?php echo $row['receiptID'].'&cid='.$row['customerID'].'&pid='.$row['proformaID']; ?>" > 
											<i class="icon-search">&nbsp;</i>
										</a>
									</td>								 														
								</tr>
                <?php		
				}
			}
			
			?></tbody></table>
           <style type="text/css">
		   	.page_link a{
				padding:5px !important;
				border:1px solid #CCC !important;
			}
			.page_link{
				margin-right:0px;
			}
		   </style>
            <div class="pagi">
             <?php
				$sqxl = "SELECT * FROM receipts ORDER BY receiptID DESC";
				$result_count = mysql_query($sqxl);
			?>
            	<div><?php echo "Record <strong>".$pageget."</strong> Of <strong>".mysql_num_rows($result_count)."</strong>"; ?></div>
                <div style="margin-bottom:10px; margin-top:20px;">
				<?php
                    echo $pager->renderFullNav();
                ?>
                </div>
            </div>
            </div>
           
                    <!-- end view invoice -->
                </div> 
                <!-- end row -->
            </div>
          <?php
	}// end showInvoice function
	
	function filterSalesman(){		
		$html = ' <!-- start invoice-salesman -->
  			<div class="tab-pane active" id="invoice-salesman">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">FILTER BY SALESMAN</h3>
                    <!-- start filter by salesman --> 
                    <div id="filterSalesman" class="rounded col_12 box_shadow box-align-center">
						<!-- start filterwrap -->   
						<div class="filterwrap">
							<form id="filtersalesm" method="post"> 
								<label>Choose Salesman</label>
								<select id="selectsalesm" name="selectsalesm">
									<option selected="selected" value="all">All</option>';
									$query_sales = "SELECT * FROM sales";
									if ($result_sales=mysql_query($query_sales)) {// check if query has contents
										while ($row_sales=mysql_fetch_array($result_sales)) {// start fetching arrays
											$html .= '<option value="'.$row_sales['salesName'].'">'.$row_sales['salesName'].'</option>'; 
										}
									}
								 $html .= '</select>
								 <button id="filtersend" name="filtersend" class="btn" type="submit"><i class="icon-search"></i> find</button>
							</form>
						</div>
						<!-- end filterwrap -->
						<!-- start filterResult -->
						<div id="filtercontent" class="filterResult">
                    	<table id="salesman-filter-table" name="salesman-filter-table" class="table table-striped table-hover">
							<thead>
								<tr>	
									<td>Salesman</td>
									<td>Proforma ID</td>	
									<td>Customer Name</td>	
									<td>Job Title</td>
									<td>P.O Box</td>
									<td>Address</td>
									<td>Mobile Number</td>									
									<td>Items</td>														
								</tr>
							</thead>
							<tbody>';
								$sql_receipts = "SELECT * FROM receipts";
								if ($result_receipts=mysql_query($sql_receipts)) {// check if query has contents
									while ($row_receipts=mysql_fetch_array($result_receipts)) {// start fetching arrays 
										$html .= '<tr>
												<td>'.$row_receipts['salesman'].'</td>
												<td>'.$row_receipts['proformaID'].'</td>	
												<td>'.$row_receipts['custName'].'</td>	
												<td>'.$row_receipts['custJobTitle'].'</td>
												<td>'.$row_receipts['custPO'].'</td>
												<td>'.$row_receipts['custLocation'].'</td>
												<td>'.$row_receipts['custNumb'].'</td>												
												<td><a data-toggle="modal" href="inc/invoice/showitems.inc.php?sid='.$row_receipts['proformaID'].'" data-target="#modal_filter">show items</a></td>														
											</tr>';
									}
								}
							$html .= '</tbody>
							</table>
						</div>
						<!-- end filterResult -->
                    </div>
                    <!-- end filter by salesman -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end invoice-salesman	-->';
		echo $html;
	}// end filterSalesman function
	
	function filterDate(){		
		$html = ' <!-- start invoice-date -->
  			<div class="tab-pane active" id="invoice-date">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">FILTER BY DATE</h3>
                    <!-- start filter by date --> 
                    <div id="filterDate" class="rounded col_12 box_shadow box-align-center">
						<!-- start filterwrap -->   
						<div class="filterwrap">
							<form id="filterdate" method="post"> 
								<label>Choose Date</label>
								 <input type="text" id="pickdate" size="30" />
								 <button id="filtersend" name="filtersend" class="btn" type="submit"><i class="icon-search"></i> find</button>
							</form>
						</div>
						<!-- end filterwrap -->
						<!-- start filterResult -->
						<div id="filtercontent" class="filterResult">
                    	<table id="date-filter-table" name="date-filter-table" class="table table-striped table-hover">
							<thead>
								<tr>	
									<td>Date</td>
									<td>Salesman</td>
									<td>Proforma ID</td>	
									<td>Customer Name</td>	
									<td>Job Title</td>									
									<td>Address</td>
									<td>Mobile Number</td>									
									<td>Items</td>														
								</tr>
							</thead>
							<tbody>';
								$sql_receipts = "SELECT * FROM receipts";
								if ($result_receipts=mysql_query($sql_receipts)) {// check if query has contents
									while ($row_receipts=mysql_fetch_array($result_receipts)) {// start fetching arrays 
										$html .= '<tr>
												<td>'.$row_receipts['receiptDate'].'</td>
												<td>'.$row_receipts['salesman'].'</td>
												<td>'.$row_receipts['proformaID'].'</td>	
												<td>'.$row_receipts['custName'].'</td>	
												<td>'.$row_receipts['custJobTitle'].'</td>												
												<td>'.$row_receipts['custLocation'].'</td>
												<td>'.$row_receipts['custNumb'].'</td>												
												<td><a data-toggle="modal" href="inc/invoice/showitems.inc.php?sid='.$row_receipts['proformaID'].'" data-target="#modal_filter">show items</a></td>														
											</tr>';
									}
								}
							$html .= '</tbody>
							</table>
						</div>
						<!-- end filterResult -->
                    </div>
                    <!-- end filter by date -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end invoice-date	-->';
		echo $html;
	}// end filterdate function
	
	// salesman - add
	function salesmanAdd(){
		$html ='<div class="tab-pane active" id="salesman-add">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">ADD SALESMAN</h3>
                    <!-- start add salesman form -->
                    <div class="rounded  box_shadow box-align-center">                
            <form action="inc/salesmen/addsalesman.inc.php" method="post">
              <fieldset>               
                
                 <label>Salesman Name</label>
                <input type="text" name="sName" id="sName">
                
                 <label>Email</label>
                <input type="text" name="sEmail" id="sEmail">
               
                 <label>Username</label>
                <input type="text" name="sUser" id="sUser">
				
				<label>Password</label>
                <input type="text" name="sPass" id="sPass">
                                
                    <button type="submit" class="btn">Submit</button>
                  </fieldset>
                </form>
                    </div>
                    <!-- end add salesman form -->
                </div>
                <!-- end row -->
            </div>
            <!-- end salesman-add -->';
		echo $html;	
	}//end salesmanAdd function
	
	//salesman - edit
	function salesmanEdit(){
		$sql = "SELECT * FROM sales";
		$html = '<!-- start salesmen -view -->
  			<div class="tab-pane active" id="salesman-view">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">EDIT SALESMAN</h3>
                    <!-- start edit salesman --> 
                    <div class="rounded  box_shadow box-align-center">    
                    	<table id="salesman-edit-table" class="table table-striped table-hover">
							<thead>
								<tr>
									<td>Action</td>
									<td>Salesman Name</td>
									<td>Email</td>	
									<td>Username</td>	
									<td>Password</td>																							
								</tr>
							</thead>
							<tbody>';
			if ($result=mysql_query($sql)) {// check if query has contents
				while ($row=mysql_fetch_array($result)) {// start fetching arrays 
						$html .= '<tr>';
						$html .= '<td><a class="edit-salesman" rel="tooltip" title="Edit '.$row['salesName'].'" data-toggle="modal" href="#itemModal'.$row['salesID'].'"><i class="icon-edit"></i></a>';
						$html .= '<div id="itemModal'.$row['salesID'].'" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			<h3 id="myModalLabel">Edit Salesman</h3>
			</div>
			<form action="inc/salesmen/editsalesmen.inc.php" method="POST">
			<div class="modal-body">
						<input type="hidden" name="salesID" value="'.$row['salesID'].'"> 
						<label>Salesman Name</label>
            			<input type="text" name="sName" id="sName"  value="'.$row['salesName'].'">
             			<label>Email</label>
            			<input type="text" name="sEmail" id="sEmail"  value="'.$row['salesEmail'].'">
            			<label>Username</label>
						<input type="text" name="sUser" id="sUser"  value="'.$row['salesUser'].'">	
						<label>Password</label>
						<input type="text" name="sPass" id="sPass"  value="'.$row['salesPassword'].'">	 
						<div class="modal-footer">
							<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
							<button class="btn btn-primary" type="submit">Save changes</button>
						</div>
						</form>
					</div>';
						$html .= '</td>';
						$html .= '<td>'.$row['salesName'].'</td>	
								  <td>'.$row['salesEmail'].'</td>	
									<td>'.$row['salesUser'].'</td>
									<td>'.$row['salesPassword'].'</td>																							
								</tr>';			
				}
			}
			$html .= '</tbody></table></div>
                    <!-- end edit salesman -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end salesman-edit	-->';
		echo $html;
	}// end showCustomers function
	
	//salesman - delete
	function salesmanDelete(){
		$sql = "SELECT * FROM sales";
		$html = '<!-- start salesman-delete -->
  			<div class="tab-pane active" id="salesman-delete">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">DELETE CUSTOMERS</h3>
                    <!-- start delete salesmen --> 
                    <div class="rounded  box_shadow box-align-center">    
                    	<table id="salesman-delete-table" class="table table-striped table-hover">
							<thead>
								<tr>
									<td>Action</td>
									<td>Salesman Name</td>
									<td>Email</td>	
									<td>Username</td>	
									<td>Password</td>															
								</tr>
							</thead>
							<tbody>';
		if ($result=mysql_query($sql)) {// check if query has contents
				while ($row=mysql_fetch_array($result)) {// start fetching arrays 
					$alink = ($row['isActive'] == 1)?'<a href="inc/salesmen/deletesalesman.inc.php?action=remove&sid='.$row['salesID'].'"><i class="icon-remove"></i> remove</a>':'<a href="inc/salesmen/deletesalesman.inc.php?action=restore&sid='.$row['salesID'].'"><i class="icon-ok"></i> restore</a>';					
					$html .= '<tr>
									<td>'.$alink.'</td>
									<td>'.$row['salesName'].'</td>	
									<td>'.$row['salesEmail'].'</td>	
									<td>'.$row['salesUser'].'</td>
									<td>'.$row['salesPassword'].'</td>																							
								</tr>';
				}				
		}
				
		$html .= '</tbody></table></div>
                    <!-- end delete salesman -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end salesman-delete	-->';
		echo $html;
	}
	
	
	
	// show under construction message
	function underContruct(){
		$html = ' <!-- start product-delete -->
  			<div class="tab-pane active" id="product-delete">
            	<!-- start row -->
            	<div class="row">
                	<h3 class="economicaBold">COMING SOON</h3>
                    <!-- start delete products --> 
                    <div class="rounded  box_shadow box-align-center">    
                    	This page is under construction
                    </div>
                    <!-- end delete products -->
                </div> 
                <!-- end row -->
            </div> 	
            <!-- end product-delete	-->';
		echo $html;
		
	}
	
	function showProductUpdate_data($id){
		$getinfo = mysql_query("SELECT * FROM items WHERE itemId = $id");
		$row = mysql_fetch_array($getinfo);
		$dim = ($row['dimmable'] == 1)?'<option value="1" selected="selected">Yes</option><option value="0">No</option>':'<option value="1">Yes</option><option value="0" selected="selected">No</option>';
	?>
    
    <script type="text/javascript">
			function ChooseCategory(caption,val){
				if(document.getElementById(val.id).checked==true){
					var findnow = $('.cateholder div.cateholder_canvas').find('#_cat_'+val.value).attr('class');
					if(!findnow){
					var oldcon = $('.cateholder div.cateholder_canvas').html();
				$('.cateholder div.cateholder_canvas').html(oldcon+"<div class=\"cateholder_ele\" id=\"_cat_"+val.value+"\"><a href=\"javascript:void(0)\" onclick=\"RemoveCatSel('_cat_"+val.value+"')\"><i class=\"icon-remove-sign\"></i> "+caption+"</a><input type=\"hidden\" name=\"addcat[]\" id=\"cat_"+val.value+"\" value=\""+val.value+"\" /></div>");
					}else{
						return false;
					}
				}else{
					$('#_cat_'+val.value).remove();
				}
				
			}
			function RemoveCatSel(obj){
				$('#'+obj).remove();
			}
			function Try(){
				for(var cnt = 1;cnt<=$('#catcnter').val();cnt++){
					document.getElementById('cat_check_'+cnt).checked = false;
				}
			}
		</script>
    
    			<div class="tab-pane active row" id="product-update">  
            	<div class="wide ">
                <a href="led-master.php?mngr=prod&subpg=update" style="float:right; padding-top:5px;">Back &raquo;</a>
                	<div class="">
                    
                    <h3 class="economicaBold">UPDATE PRODUCT</h3></div>
                    <div class="rounded  box_shadow box-align-center">
                    	<form action="adminUpdate.php" method="POST" enctype="multipart/form-data">
                        <div class="j-add-left">	
						<input type="hidden" name="targetItem" value="<?php echo $row['itemId']; ?>"> 
						<label>MAG Description</label>
            			<input type="text" name="magDesc" id="magDesc"  value="<?php echo $row['magDesc']; ?>">
                       
                         
                          <label>Category</label>
                          
                 <a class="updateLink" rel="tooltip" title="Images" data-toggle="modal" href="#img_itemModal_add_category" onclick="Try()"><i class="icon-plus-sign"></i> Add Category</a>
                 <div class="cateholder">
                 	<div class="cateholder_canvas">
                        
                        <?php
							$getcats = mysql_query("SELECT c.cat_id, cc.`name` FROM cat_items c LEFT JOIN category cc ON cc.id = c.cat_id LEFT JOIN items i ON i.itemId = c.item_id WHERE c.item_id = ".$row['itemId']);
							while($cats_row = mysql_fetch_array($getcats)){
						?>
                        	<div class="cateholder_ele" id="_cat_<?php echo $cats_row['cat_id']; ?>"><a href="javascript:void(0)" onclick="RemoveCatSel('_cat_<?php echo $cats_row['cat_id']; ?>')"><i class="icon-remove-sign"></i> <?php echo $cats_row['name']; ?></a><input type="hidden" name="addcat[]" id="cat_<?php echo $cats_row['id']; ?>" value="<?php echo $cats_row['cat_id']; ?>" /></div>
                            
                        <?php
							}
						?>
                        
                        
                    </div>
                    <div class="clear"></div>
                 </div>
                 <div id="img_itemModal_add_category" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-header">
                        <h1>Select Categories</h1>
                        <div style="height:350px; overflow-y:auto;">
                        <ul class="j-categories">
                      		<?php
							$categories = mysql_query("SELECT * FROM category WHERE parent is NULL ORDER BY name");
							$cnter = 0;
							while($catrow = mysql_fetch_array($categories)){
								$cnter++;
								
							?>
                            <li>	
                            	<?php
									$checkifpar = mysql_query("SELECT id FROM category WHERE parent = ".$catrow['id']);
									$able = (mysql_num_rows($checkifpar))? "disabled = \"disabled\"" : NULL;
								?>
                            	 <input type="checkbox" id="cat_check_<?php echo $cnter; ?>" value="<?php echo $catrow['id'] ?>" onclick="ChooseCategory('<?php echo $catrow['name']; ?>',this)" <?php echo $able; ?>>&nbsp;&nbsp;<?php echo $catrow['name']; ?>
                                <?php
									if(mysql_num_rows($checkifpar)){
                                		$getchild = ShowChild_PopUp($catrow['id'],$cnter);
										echo $getchild ['str'];
										$cnter = $getchild ['cnt'];
									}
									
                                ?>
                                
                                
                            </li>
                            <?php	
                                }
                            ?>
                            
                        </ul>
                        </div>
                        <input type="hidden" id="catcnter" value="<?php echo $cnter; ?>" />	
                        </div>
                         	<div class="modal-footer">
								<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 			
							</div>
                   </div>
                 
                         
                       
             			<label>PH Code</label>
            			<input type="text" name="phCode" id="phCode"  value="<?php echo $row['phCode']; ?>">
            			<label>Item Name</label>
						<input type="text" name="itemName" id="itemName"  value="<?php echo $row['itemName']; ?>">	
						<label>Item Description</label>
						<input type="text" name="itemDesc" id="itemDesc"  value="<?php echo $row['itemDesc']; ?>">	
						<label>Item Price</label>
						<input type="text" name="itemPrice" id="itemPrice"  value="<?php echo $row['itemPrice']; ?>">	
						 <label>Wattage</label>
						<input type="text" name="watts" id="watts"  value="<?php echo $row['wattage']; ?>">
						<label>Comparable Halogen Wattage</label>
						<input type="text" name="chw" id="chw"  value="<?php echo $row['halogenWatt']; ?>">
						<label>Socket</label>
						<input type="text" name="socket" id="socket"  value="<?php echo $row['socket']; ?>">
						<label>Beam Intensity</label>
						<input type="text" name="binsten" id="binsten"  value="<?php echo $row['beamInt']; ?>">
						<label>Beam Angle</label>
						<input type="text" name="bangle" id="bangle"  value="<?php echo $row['beamAngle']; ?>">
                        </div>
                        <div class="j-add-left">		
                        <label>LifeTime</label>
						<input type="text" name="lifetime" id="lifetime"  value="<?php echo $row['lifetime']; ?>">
						<label>Dimmable*</label>
						<select name="dimmable" id="dimmable"><?php echo $dim; ?></select>            
						<label>Lumen Output</label>
						<input type="text" name="lumout" id="lumout"  value="<?php echo $row['lumenOutput']; ?>">						
						<label>Efficacy</label>
						<input type="text" name="effi" id="effi"  value="<?php echo $row['efficacy']; ?>">						
						<label>Units Per Pack</label>
						<input type="text" name="upp" id="upp"  value="<?php echo $row['unitsPerPack']; ?>">						
						 <label>Color Rendering Index</label>
						<input type="text" name="cri" id="cri"  value="<?php echo $row['colorRendering']; ?>">						
						<label>Color Temperature</label>
						<input type="text" name="colorTemp" id="colorTemp"  value="<?php echo $row['colorTemp']; ?>">						
						<label>12NC 929000</label>
						<input type="text" name="nc" id="nc"  value="<?php echo $row['NC']; ?>">	
                       
                        		
                        <label>Product Image</label>
                        
                        
                        
                        <p style="margin-bottom:5px;"><a class="updateLink" rel="tooltip" title="Images" data-toggle="modal" href="#img_itemModal<?php echo $row['itemId']; ?>"><?php echo "View Image"; ?></a></p>
                        
                        <input type="hidden" name="old_img" value="<?php echo $row['image']; ?>" />
                        
						<input id="lefile_edit" type="file" name="pimg_edit" style="display:none">
						<div class="input-append">
						   <input id="photoCover_edit" class="input-large" type="text">
						   <a class="btn" onclick="$('input[id=lefile_edit]').click();">Browse</a>
						</div>
						 
						<script type="text/javascript">
						$('input[id=lefile_edit]').change(function() {
						   $('#photoCover_edit').val($(this).val());
						});
						</script>
                        
                        <div id="img_itemModal<?php echo $row['itemId']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-header">
                      
                        <?php if(strlen($row['image'])>0){ ?>
                       		<img src="<?php echo str_replace("../../","",$row['image']); ?>" />
                        <?php }else{ ?>
                        	<img src="productimages/noimage.jpg" />
                        <?php } ?>
                        </div>
                         	<div class="modal-footer">
								<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>			
							</div>
                    	</div>
                        			
						   <div style="margin-top:20px;">
                           	<button class="btn btn-primary" type="submit">Save changes</button>
							
							
						</div>
                       </div>
                       <div class="clear"></div>
						
						</form>
				</div>	
               </div>	
              </div>
              	
           
        
    <?php
	}
	
	function showCustomersAdd(){
	?>
    		<div class="tab-pane active row" id="product-update">  
            	<div class="wide ">
                	<div class=""><h3 class="economicaBold">ADD CUSTOMER</h3></div>
                    <div class="rounded  box_shadow box-align-center">
                    
                    	<form action="inc/customers/addcustomer.inc.php" method="POST">
						<div class="j-add-left">
						<input type="hidden" name="targetCustomer" value=""> 
						<label>Customer Name</label>
            			<input type="text" name="cName" id="cName" placeholder="Customer Name"  value="">
             			<label>Job Title</label>
            			<input type="text" name="cJobTitle" id="cJobTitle" placeholder="Job Title"  value="">
            			<label>Location</label>
						<input type="text" name="cLocation" id="cLocation"  placeholder="Location" value="">	
                        <label>P.O Box</label>
						<input type="text" name="cPO" id="cPO"  value="" placeholder="P.O Box" >
						</div>
                        <div class="j-add-left">
                        	
						<label>Email</label>
						<input type="text" name="cEmail" id="cEmail"  value="" placeholder="Email">	
						 <label>Mobile Number</label>
						<input type="text" name="cNumber" id="cNumber"  value="" placeholder="Mobile Number">
						<label>Company Name</label>
						<input type="text" name="cCompName" id="cCompName"  value="" placeholder="Company Name">					 						
						<p>
						
							
							<button class="btn btn-primary" type="submit">Save changes</button>
                         </p>
						</div>
                        <div class="clear"></div>
						</form>
                    
                    </div>
                </div>
            </div>
    <?php
	}
	
	function CatView(){
		if(@$_GET['delid']){
			mysql_query("DELETE FROM cat_fetures WHERE cat_id = ".$_GET['delid']);
			mysql_query("DELETE FROM category WHERE id = ".$_GET['delid']);
	}
	
	
?>
	<script type="text/javascript">
		function DelConfirm(url){
			if(confirm("Are you sure you want to delete data?")){
				window.location = url;
			}else{
				return false;
			}
		}
	</script>
    
    <link rel="stylesheet" href="treeview/jquery.treeview.css" />
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
	<script src="treeview/jquery.treeview.js"></script>
    <script src="treeview/demo/jquery.cookie.js"></script>

	<script type="text/javascript" src="treeview/demo/demo.js"></script>
    
		<div class="tab-pane active row" id="product-update">  
            	<div class="wide ">
                	<div class=""><h3 class="economicaBold">CATEGORIES</h3></div>
                    <div class="rounded  box_shadow box-align-center">
                    	
                        <?php
							echo RenderTree();
						?>
                        
                    </div>
                 </div>
         </div>
<?php	
	}
	
	function CatAdd(){
		$btname = "addcatSBn";
		if(@$_GET['id']){
			$getinfo = mysql_query("SELECT * FROM category WHERE id = ".$_GET['id']);
			$infocat = mysql_fetch_array($getinfo);
			$btname = "editcatSBn";
		}
	
		if(isset($_POST['addcatSBn'])){
			if($_FILES["cat_img"]["name"]){
			$acceptfile = array('jpg','jpeg','png');
			$gettype = explode(".",$_FILES["cat_img"]["name"]);
				if(in_array($gettype[1],$acceptfile)){
						$target_path = "productimages/";	
						$target_path_ = $target_path .'cat'. basename($_FILES['cat_img']['name']); 
						if(move_uploaded_file($_FILES['cat_img']['tmp_name'], $target_path_)) {
							$target_path = $target_path_;
						}else{
							$err = "Uploading file error";
						}
						
				}else{
					$err = "Invalid File Format";
				}			
			}
			$parent = @$_POST['category_add'];
			$type = @$_POST['dim'];
			$target_path = (@$target_path)? "'$target_path'" : 'NULL';
			
			$res = mysql_query("INSERT into category SET name = '".$_POST['catname']."', parent = $parent, type = '$type', image = $target_path");
			$lastid = mysql_insert_id();
			if($res){
				$features = @$_POST['catfet'];
				for($cnt=0;$cnt<count($features);$cnt++){
					if($features[$cnt]){
						mysql_query("INSERT INTO cat_fetures SET cat_id = $lastid, fet_id = ".$features[$cnt]);
					}
				}
				
				echo "<script type=\"text/javascript\">
					window.location = \"led-master.php?mngr=cat&subpg=view\"
				</script>";
			}
		}else if(isset($_POST['editcatSBn'])){
			
			if($_FILES["cat_img"]["name"]){
				$acceptfile = array('jpg','jpeg','png');
				$gettype = explode(".",$_FILES["cat_img"]["name"]);
				if(in_array($gettype[1],$acceptfile)){
						$target_path = "productimages/";	
						$target_path_ = $target_path .'cat'. basename($_FILES['cat_img']['name']); 
						if(move_uploaded_file($_FILES['cat_img']['tmp_name'], $target_path_)) {
							$target_path = $target_path_;
						}else{
							$err = "Uploading file error";
						}
						
				}else{
					$err = "Invalid File Format";
				}			
			}
			$oldimg = (@$_POST['old_img_edit'])? "'".@$_POST['old_img_edit']."'" : 'NULL';
			$target_path = (@$target_path)? "'$target_path'" : $oldimg;
			$parent = @$_POST['category_add'];
			$type = @$_POST['dim'];
			
			$res = mysql_query("UPDATE category SET name = '".$_POST['catname']."', parent = $parent, type = '$type', image = $target_path WHERE id = ".$_POST['editcatid']);
			if(@$res){
				
				$features = @$_POST['catfet'];
				$delres = mysql_query("DELETE FROM cat_fetures WHERE cat_id = ".$_POST['editcatid']);
				for($cnt=0;$cnt<count($features);$cnt++){
					if($features[$cnt]){
						mysql_query("INSERT INTO cat_fetures SET cat_id = ".$_POST['editcatid'].", fet_id = ".$features[$cnt]);
					}
				}
				
				echo "<script type=\"text/javascript\">
					window.location = \"led-master.php?mngr=cat&subpg=view\"
				</script>";
			}	
		}
		
		function SelectedParent($cat,$id = NULL){
			if($id){
				$check = mysql_query("SELECT COUNT(id) as cnt FROM category WHERE id = $id");
				$check_val = mysql_fetch_array($check);
				if($check_val >=1){
					if($cat == $id){
						return "selected";
					}else{
						return NULL;
					}
				}
			}
		}
		
	
		
?>
		<script type="text/javascript">
			function ShowOtherField(obj){
				if(obj.value.length > 0){
					$('#otherfield_').fadeIn(200);
				}else{
					$('#otherfield_').fadeOut(200);
				}
			}
		</script>
		<div class="tab-pane active row" id="product-update">  
            	<div class="wide ">
                	<div class=""><h3 class="economicaBold"><?php echo (@$_GET['id'])? "EDIT" : "ADD"; ?> CATEGORIES</h3></div>
                    <div class="rounded  box_shadow box-align-center">
                    	<form method="post" enctype="multipart/form-data" action="">
                        	<div class="left">
                                <label>Category Name</label>
                                <input type="text" name="catname" id="catname" value="<?php echo (@$_GET['id'])? $infocat['name'] : @$_POST['catname']; ?>">
                                <input type="hidden" name="editcatid" value="<?php echo (@$_GET['id'])? $infocat['id'] : NULL; ?>" />
                                <p>
                                     <label>Category Parent</label>
                                    <select name="category_add" onchange="ShowOtherField(this)">
                                        <option value="">-No Parent-</option>
                                    <?php
                                        $parentlist = mysql_query("SELECT * FROM category");
                                        while($parlist = mysql_fetch_array($parentlist)){
                                    ?>
                                            <option value="<?php echo $parlist['id']; ?>" <?php echo SelectedParent($parlist['id'],@$infocat['parent']);  ?>><?php echo $parlist['name']; ?></option>
                                    <?php		
                                        }
                                    ?>
                                </select>
                                <?php echo SelectedParent(@$infocat['id']);  ?>
                                </p>
                              
                                
                            </div>
                            <?php
								$showf = (@$infocat['parent'])? NULL : "display:none;"; 
							?>
                            <div class="left" id="otherfield_" style="padding-left:30px; <?php echo $showf; ?>">
                            	<label>Dimmable?</label>
                                <select name="dim">
                                	<option value=""></option>
                                	<option value="Y" <?php if(@$infocat['type'] == 'Y') echo "selected"; ?>>Yes</option>
                                    <option value="N" <?php if(@$infocat['type'] == 'N') echo "selected"; ?>>No</option>
                                    <option value="B" <?php if(@$infocat['type'] == 'B') echo "selected"; ?>>Both</option>
                                </select>
                               		<label>Upload Image</label>
                                    <input type="hidden" name="old_img_edit" value="<?php echo $infocat['image']; ?>"  />
                                	<input id="lefile_edit" type="file" name="cat_img" style="display:none">
                                    <div class="input-append">
                                       <input id="photoCover_edit" class="input-large" type="text">
                                       <a class="btn" onclick="$('input[id=lefile_edit]').click();">Browse</a>
                                    </div>
                                     
                                    <script type="text/javascript">
                                    $('input[id=lefile_edit]').change(function() {
                                       $('#photoCover_edit').val($(this).val());
                                    });
                                    </script>
                                
                            </div>
                            
                            <div class="right" style="padding-right:0px;">
                            	<?php
								if(@$infocat['image']){
								?>
                            		<img src="<?php echo @$infocat['image']; ?>" class="thumb" width="150" />
                                <?php
								}else{
								?>
                             	  <img src="productimages/noimage.jpg" class="thumb" width="150" />
                                <?php
								}
								?>
                            </div>
                            
                            <div class="clear"></div>
                            
                            <div align="left" style="padding-bottom:15px;">
                            	<label>Features</label>
                            	<?php
									$features = mysql_query("SELECT * FROM features ORDER BY name");
									while($flist = mysql_fetch_array($features)){
										$ifhas = mysql_query("SELECT * FROM cat_fetures WHERE cat_id = ".$infocat['id']." AND fet_id = ".$flist['id']."");
										$fetcheck = (mysql_num_rows($ifhas)>0)? "checked=\"checked\"" : NULL;
 							?>
                            		<input type="checkbox" name="catfet[]" value="<?php echo $flist['id']; ?>" style="margin-top:-2px;" <?php echo $fetcheck; ?> /> <?php echo $flist['name']; ?>
                                    &nbsp;
                                    &nbsp;
                                    &nbsp;
                            <?php		
									}
								?>	
                            </div>
                            
                            <div align="left">
                            	<p>
                                <button class="btn btn-primary" name="<?php echo $btname; ?>" type="submit">Save Category</button>
                                </p>
                            </div>
                        </form>
                    </div>
                </div>
        </div>
<?php	
	}
	
	
	function EditCustomerData(){
		if(isset($_POST['editcustomer'])){
			$cName = $_POST['cName'];
			$cJobTitle = $_POST['cJobTitle'];
			$cLocation = $_POST['cLocation'];
			$cPO = $_POST['cPO'];
			$cEmail = $_POST['cEmail'];
			$cNumber = $_POST['cNumber'];
			$cCompName = $_POST['cCompName'];
			$sql = "UPDATE customers SET cName='$cName', cJobTitle='$cJobTitle', cLocation='$cLocation', cPO='$cPO', cEmail='$cEmail', cNumber='$cNumber', cCompName='$cCompName' WHERE customerID=".@$_GET['eid'];
			@mysql_query($sql);	
			echo "<script type=\"text/javascript\">
					window.location = \"led-master.php?mngr=cust&subpg=view&action=custeditsuccess\"
				</script>";
		}
		
		$sql = mysql_query("SELECT * FROM customers WHERE customerID = ".@$_GET['eid']);
		$data = mysql_fetch_array($sql);
?>
	<div class="tab-pane active" id="customer-view">
            	
            	<div class="row">
                <a style="float:right; padding-top:5px;" href="led-master.php?mngr=cust&amp;subpg=view">Back »</a>
                	<h3 class="economicaBold">EDIT CUSTOMERS</h3>
                    	
                    <div class="rounded  box_shadow box-align-center">  
                    	<form method="post">
                        	<label>Name</label>
                            <input type="text" name="cName" value="<?php echo @$data['cName'] ?>" />
                            <label>Job Title</label>
                            <input type="text" name="cJobTitle" value="<?php echo @$data['cJobTitle'] ?>" />
                            <label>P.O. Box</label>
                            <input type="text" name="cPO" value="<?php echo @$data['cPO'] ?>" />
                             <label>Location</label>
                            <input type="text" name="cLocation" value="<?php echo @$data['cLocation'] ?>" />
                            
                            <label>Email</label>
                            <input type="text" name="cEmail" value="<?php echo @$data['cEmail'] ?>"/>
                            <label>Mobile</label>
                            <input type="text" name="cNumber" value="<?php echo @$data['cNumber'] ?>"/>
                            <label>Company</label>
                            <input type="text" name="cCompName" value="<?php echo @$data['cCompName'] ?>"/>
                            <p>
                            	<button class="btn btn-primary" name="editcustomer" type="submit">Save Changes</button>
                            </p>
                        </form> 
                    </div>
               </div>
     </div>
<?php

	}
	
	function featview(){
		
?>
	<script type="text/javascript">
			function RemoveItemJ(url){
				if(confirm('Move item to trash?')){
					window.location = url;
				}else{
					return false;
				}
			}
		</script>
	<div class="tab-pane active" id="customer-view">
            	
            	<div class="row">
                	<h3 class="economicaBold">FEATURES</h3>
                    	
                    <div class="rounded  box_shadow box-align-center"> 
                    
                    	<table width="100%" border="0" id="product-update-table" class="table table-striped table-hover">
                        	<tr>
                            	<td width="90%"><strong>Name</strong></td>
                            	<td width="10%"><strong>Action</strong></td>
                            </tr>
                            <?php
							$list = mysql_query("SELECT * FROM features ORDER BY id DESC");
							while($lrow = mysql_fetch_array($list)){
							?>
                            <tr>
                            	<td ><?php echo $lrow['name']; ?></td>
                                <td ><a href="led-master.php?mngr=feat&subpg=update&id=<?php echo $lrow['id']; ?>" title="edit" class="updateLink"><i class="icon-pencil"></i></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:void(0);" title="delete" class="updateLink" onclick="RemoveItemJ('led-master.php?mngr=feat&subpg=update&did=<?php echo $lrow['id']; ?>')"><i class="icon-trash"></i></a></td>
                            </tr>
                            <?php
							}
							?>
                        </table>
                    </div>
                </div>
    </div>
<?php
	}
	function featadd(){
		
		$btnname = "addfeatures";
		if(@$_GET['subpg']=='update' && @$_GET['id']){
			$btnname = "editfeatures";
			$getdata = mysql_query("SELECT * FROM features WHERE id = ".@$_GET['id']);
			$featrow = mysql_fetch_array($getdata);
		}
		
		if(isset($_POST['editfeatures'])){
			$res = mysql_query("UPDATE features SET name = '".@$_POST['featname']."' WHERE id = ".@$_GET['id']);
			if($res){
				echo "<script type=\"text/javascript\">
					window.location = \"led-master.php?mngr=feat&subpg=view&action=custeditsuccess\"
				</script>";	
			}
		}
		
		if(isset($_POST['addfeatures'])){
			$name = @$_POST['featname'];
			if($name){
				$res = mysql_query("INSERT INTO features SET name = '$name'");
				if($res){
				echo "<script type=\"text/javascript\">
					window.location = \"led-master.php?mngr=feat&subpg=view&action=custeditsuccess\"
				</script>";
				}
			}
		}
		
		if(@$_GET['did']){
			$res = mysql_query("DELETE FROM features WHERE id = ".@$_GET['did']);
			if($res){
				echo "<script type=\"text/javascript\">
					window.location = \"led-master.php?mngr=feat&subpg=view&action=custeditsuccess\"
				</script>";	
			}
		}
?>
	
	<div class="tab-pane active" id="customer-view">
            	
            	<div class="row">
                <a style="float:right; padding-top:5px;" href="led-master.php?mngr=feat&amp;subpg=view">Back »</a>
                	<h3 class="economicaBold">ADD FEATURES</h3>
                    	
                    <div class="rounded  box_shadow box-align-center"> 
                    
                    	<form method="post">
                        	<p>
                            	Feature's Name<br/>
                                <input type="text" name="featname" value="<?php echo @$featrow['name']; ?>" />
                            </p>
                            <p>
                            	<button class="btn btn-primary" name="<?php echo $btnname; ?>" type="submit">Save Changes</button>
                            </p>
                        </form>
                    </div>
                </div>
    </div>
<?php	
	}
	 
?>